#include <iostream>
#include <string>
#include <cmath>
using namespace std;
string s;
int n, t;

int main()
{
	ios::sync_with_stdio(false);
	int t;
	cin >> t;
	for (int ti = 1; ti <= t; ti++) {
		cout << "Case #" << ti << ":\n";
		getline(cin, s);
		getline(cin, s);
		cin >> n;
		int len = s.length(), si = 0;
		int line = ceil(float(len)/n), last = len%n;
		char ch[line][n];
		for (int j = 0; j < last; j++) {
			for (int i = 0; i < line; i++) ch[i][j] = s[si++];
		}
		if (len%n != 0) line--;
		for (int j = last; j < n; j++)
			for (int i = 0; i < line; i++) ch[i][j] = s[si++];
		for (int i = 0; i < line; i++)
			for (int j = 0; j < n; j++) cout << ch[i][j];
		if (len%n != 0)
			for (int j = 0; j < last; j++) cout << ch[line][j];
		cout << "\n";
	}
}


